﻿Public Class viewProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim userName As String
        Dim viewingOwnProfile As Boolean
        Dim um As UserModel
        If IsNothing(Request.Params("UserName")) Then
            If Not User.Identity.IsAuthenticated Then
                placeholder_genericTitle.Visible = True
                placeholder_notLoggedIn.Visible = True
                Return
            Else
                userName = User.Identity.Name
            End If
        Else
            userName = Request.Params("UserName")
        End If

        viewingOwnProfile = userName = User.Identity.Name

        um = New UserModel(userName)

        If Not (um.IsSaved) Then
            placeholder_genericTitle.Visible = True
            placeholder_cantFind.Visible = True
        Else
            If um.IsEmpty Then
                placeholder_genericTitle.Visible = True
                If viewingOwnProfile Then
                    placeholder_yoursNotCreated.Visible = True
                Else
                    placeholder_userNotCreated.Visible = True
                    lbl_userNotCreated.Text = userName
                End If
            Else
                placeholder_profile.Visible = True
                lbl_profileTitle.Text = If(viewingOwnProfile, "My profile", userName & "'s profile")
                img_profilePicture.ImageUrl = um.Picture
                lbl_fullName.Text = um.FullName
                lbl_description.Text = um.Description
            End If
            If viewingOwnProfile Then
                placeholder_editProfile.Visible = True
            End If
        End If
    End Sub

    Protected Sub btn_editMyProfile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_editMyProfile.Click
        Response.Redirect("~/editProfile.aspx")
    End Sub
End Class